package com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount {

    private double overdraft = 0;

    public CheckingAccount(double amount) {
        super(amount);
    }

    public CheckingAccount(double amount, double overdraft) {
        super(amount);
        if (overdraft < 0){
            throw new IllegalArgumentException("Negative overdraft");
        }

        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double amount) throws OverDraftLimitExceededException {


        if (overdraft + balance < amount) {
            throw new OverDraftLimitExceededException(this);//TODO ADD CLIENT!!!!
        }

        if (amount <= balance) {
            balance -= amount;
            return;
        }


        overdraft -= amount - balance;
        balance = 0;

    }

    @Override
    public double maximumAmountToWithdraw() {
        return balance + overdraft;
    }


}
